package iiris

import (
	"gitee.com/tietang/terrace-go/v2/base"
	"gitee.com/tietang/terrace-go/v2/base/starter/iweb"
	"github.com/kataras/iris/v12"
)

type IrisFileServerStarter struct {
	base.BaseStarter
}

func (s *IrisFileServerStarter) Init(ctx base.StarterContext) {
	conf := ctx.Props()
	iweb.InjectEnv(conf)
}

func (s *IrisFileServerStarter) Setup(ctx base.StarterContext) {
	app := Iris()
	app.Favicon("./favicon.ico")
	conf := ctx.Props()
	healthAndInfoEndpoint(conf, app)

	dirs := conf.Strings("ui.static.dirs")
	opts := iris.DirOptions{
		//Gzip: true,
		Compress: true,
	}
	for _, dir := range dirs {
		app.HandleDir("/", dir, opts)
	}
}
